package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.enums.BFeeModelEnum;
import cn.huiyunche.base.service.interfaces.BFeeModelService;
import cn.huiyunche.base.service.mappers.BFeeModelMapper;
import cn.huiyunche.base.service.model.BFeeModel;
import cn.huiyunche.base.service.model.BFeeModelExample;
import cn.huiyunche.tools.basic.exceptions.BusinessException;
import org.apache.commons.collections4.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BFeeModelServiceImpl implements BFeeModelService {

    private static final Logger LOGGER = LoggerFactory.getLogger(BFeeModelServiceImpl.class);

    @Autowired
    private BFeeModelMapper bFeeModelMapper;

    @Override
    public BFeeModel getByCode(BFeeModelEnum code) {
        LOGGER.info("getByCode parma : {}", code.getValue());

        BFeeModelExample example = new BFeeModelExample();
        example.createCriteria().andModelCodeEqualTo(code.getValue());
        List<BFeeModel> list = bFeeModelMapper.selectByExample(example);
        if (CollectionUtils.isEmpty(list)) {
            LOGGER.error("getByCode list is empty");
            throw new BusinessException("获取费用模型信息错误！");
        }
        return list.get(0);
    }

}
